﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using DatabaseHelper;
using System.IO;
using SDK10kWrapper;
using System.Configuration;
using RS232;
using UI.Online.SubForms;

namespace UI.Online
{
    public partial class frmOnlineUI2
    {
        private void LoadUI()
        {
            DisableEventButtons();
            EnableRecordButtons();
            StartAutoTimer();  

            LoadProperties();
            LoadSettings();
            LoadCamera();
            LoadRS232();
            LoadProject();
        }

        private void LoadProperties()
        {
            SurveyDataReader = new RS232Reader();
        }

        private void LoadRS232()
        {
            ConnectToSurveyData();
        }

        private void LoadSettings()
        {
            try
            {
                currProjectID = Properties.Settings.Default.CurrentProjectID;
                currProjectName = Properties.Settings.Default.CurrentPipelineName;
                currPipelineID = Properties.Settings.Default.CurrentPipelineID;
                currPipelineName = Properties.Settings.Default.CurrentPipelineName;
                currRecordID = Properties.Settings.Default.CurrentRecordID;
                currProjectLocation = Properties.Settings.Default.CurrentProjectLocation;

                SurveyDataReader.Port.PortName = Properties.Settings.Default.PortName;
                SurveyDataReader.Port.BaudRate = Properties.Settings.Default.BaudRate;
                SurveyDataReader.StringName = Properties.Settings.Default.StringName;
                SurveyDataReader.StringFormat = Properties.Settings.Default.StringFormat;
                StringFormatSelection = Properties.Settings.Default.StringFormatSelection;
                InstallationFolder = Properties.Settings.Default.InstallationFolder;
                mnuSettingsCameras1.Checked = Properties.Settings.Default.Camera1Enable;
                mnuSettingsCameras2.Checked = Properties.Settings.Default.Camera2Enable;
                mnuSettingsCameras3.Checked = Properties.Settings.Default.Camera3Enable;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void SaveSettings()
        {
            try
            {
                Properties.Settings.Default.CurrentProjectID = currProjectID;
                Properties.Settings.Default.CurrentPipelineName = currProjectName;
                Properties.Settings.Default.CurrentPipelineID = currPipelineID;
                Properties.Settings.Default.CurrentPipelineName = currPipelineName;
                Properties.Settings.Default.CurrentRecordID = currRecordID;
                Properties.Settings.Default.CurrentProjectLocation = currProjectLocation;
                Properties.Settings.Default.PortName = SurveyDataReader.Port.PortName;
                Properties.Settings.Default.BaudRate = SurveyDataReader.Port.BaudRate;
                Properties.Settings.Default.StringName = SurveyDataReader.StringName;
                Properties.Settings.Default.StringFormat = SurveyDataReader.StringFormat;
                Properties.Settings.Default.StringFormatSelection = StringFormatSelection;
                Properties.Settings.Default.InstallationFolder = InstallationFolder;
                Properties.Settings.Default.Camera1Enable = mnuSettingsCameras1.Checked;
                Properties.Settings.Default.Camera2Enable = mnuSettingsCameras2.Checked;
                Properties.Settings.Default.Camera3Enable = mnuSettingsCameras3.Checked;
                // Save all settings
                Properties.Settings.Default.Save();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }


    }
}
